const fs = require("fs");
const ds = require("./api.json");

let japis = [];
// let okApi = [];
let apiJass = "";
let content = fs.readFile("./japi.txt","utf-8",(err,data)=>{
    japis = data.split("\n").map(e => e.trim());
    // console.log(",c",japis);
    ds.forEach(d => {
        // console.log("ok",d)
        if(japis.indexOf(d.nameUS) > -1){
            // okApi.push(d);
            apiJass += `native ${d.nameUS} takes ${d.args} returns ${d.returns}`
            apiJass += "\n"
        }
    })
    fs.writeFile("../jass/japi.j",apiJass,()=>{});
})

// 生成apiDoc
let docs = [];
let allName = [];
ds.forEach(d => {
    if(d.description || d.comment || d.title){
        docs.push({
            n:d.nameUS,
            d:d.description,
            c:d.comment,
            t:d.title
        })
    }
    allName.push(d.nameUS)
})

console.log(ds.length,allName.length)
fs.writeFile("all.json",JSON.stringify(docs),()=>{})
fs.writeFile("allName.json",JSON.stringify(allName),()=>{})
